import {createRouter,createWebHistory} from 'vue-router'
import Login from '../views/Login.vue'
import ModifyPwd from '../views/ModifyPwd.vue'
import Salary from '../views/Salary.vue'    
import StaffInfo from '../views/StaffInfo.vue'
import Staff from '../views/Staff.vue'

const routes=[
    {
        path:'/',
        redirect:'/login'
    },
    {
        path:'/login',
        name:'login',
        component:Login
    },
    {
        path:'/modifyPwd',
        name:'modifyPwd',
        component:ModifyPwd
    },
    {
        path:'/salary',
        name:'salary',
        component:Salary,
        meta:{
            needLogin:true
        }
    },
    {
        path:'/staffInfo/:id',
        name:'staffInfo',
        component:StaffInfo,
        meta:{
            needLogin:true
        }
    },
    {
        path:'/staff',
        name:'staff',
        component:Staff,
        meta:{
            needLogin:true
        }
    },
]
const router = createRouter({
    history:createWebHistory(),
    routes:routes
})
router.beforeEach((to,from,next) => {
    if(to.meta.needLogin&&!sessionStorage.getItem('user')){
        alert('请先登录');
        next('/login');
        return;
    }
    next();
})
export default router;